from collections import OrderedDict

from django.shortcuts import render

# Create your views here.

from django.views import View

# 定义广告首页
from contents.models import ContentCategory
from contents.utils import get_categories
from goods.models import GoodsChannel


class IndexView(View):

   def get(self,request):
       """提供首页广告界面"""
       #查询商品频道分类

       # 查询商品频道和分类
       categories = get_categories()

       # 获取首页广告数据
       contents={}
       content_categories = ContentCategory.objects.all()
       for cat in content_categories:
           contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')
       # 渲染模板上下文
       context = {
        'categories':categories,
        'contents':contents
       }

       return render(request,'index.html',context)
